import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)

const routes = [{
    path: '/',
    name: 'Home',
    component: Home
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/Login.vue'),
    meta: {
      title: ''
    },
  },
  {
    path: '/successful',
    name: 'successful',
    component: () => import('../views/successful.vue')
  },
  {
    path: '/price',
    name: 'price',
    component: () => import('../views/price.vue'),
    meta: {
      title: '价格与版本-魔法云'
    },
  },
  {
    path: '/about',
    name: 'about',
    component: () => import('../views/about.vue'),
    meta: {
      title: '关于我们-魔法云'
    },
  }, {
    path: '/custom-programs',
    name: 'custom-programs',
    component: () => import('@/views/custom-programs/custom-programs'),
    meta: {
      title: '企业内训-远程培训系统，打造企业内训大学。'
    },
  },
  {
    path: '/events-live',
    name: 'events-live',
    component: () => import('@/views/events-live/events-live'),
    meta: {
      title: '直播带货-线上线下同步进行，让活动无限可能。'
    },
  },
  {
    path: '/enterprise-live',
    name: 'enterprise-live',
    component: () => import('@/views/enterprise-live/enterprise-live'),
    meta: {
      title: '政企直播-政务直播、企业直播一站式解决方案'
    },
  },
  {
    path: '/marketing-talk',
    name: 'marketing-talk',
    component: () => import('@/views/marketing-talk/marketing-talk'),
    meta: {
      title: '营销拓客-跨平台营销，更全面的玩法解决您的经营难题。'
    },
  },
  {
    path: '/online-education',
    name: 'online-education',
    component: () => import('@/views/online-education/online-education'),
    meta: {
      title: '在线教育-教育机构线上线下招生引流，转化续费。'
    },
  },
  {
    path: '/activity-live',
    name: 'activity-live',
    component: () => import('@/views/activity-live/activity-live'),
    meta: {
      title: '在线教育-教育机构线上线下招生引流，转化续费。'
    },
  },
 
  {
    path: '/meeting-live',
    name: 'meeting-live',
    component: () => import('@/views/meeting-live/meeting-live'),
    meta: {
      title: '在线教育-教育机构线上线下招生引流，转化续费。'
    },
  },
  {
    path: '/pay-for-knowledge',
    name: 'pay-for-knowledge',
    component: () => import('@/views/pay-for-knowledge/pay-for-knowledge'),
    meta: {
      title: '知识付费-立刻拥有自己的知识店铺，全网互动分销。'
    },
  },
  {
    path: '/thost',
    name: 'thost',
    component: () => import('@/views/thost/thost'),
    meta: {
      title: '知识付费-全国伙伴正在招募中，与魔法云一起开启亿万市场'
    },
  },
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes,
  scrollBehavior(to, from, savedPosition) {
    // console.log(to, from, savedPosition);
    return new Promise((resolve) => {
      if (savedPosition) {
        resolve(savedPosition)
      } else {
        if (to.hash) {
          console.log(to.hash)
          setTimeout(() => {
            resolve({
              selector: to.hash
            })
          }, 400);
        } else {
          resolve({
            x: 0,
            y: 0
          })
        }
      }
    })
  },
})

router.beforeEach((to, from, next) => {
  /* 路由发生变化修改页面title */
  document.title = to.meta.title || '魔法云-在线教育直播-知识付费-企业直播-网校系统-直播课堂';

  wclient.initJSSDK({
      mpid: "MFU",
      mpbrokerBaseurl: "//s1.mpwork.com"
    },
    () => {
      wclient.setupShare({
          msgtype: "appmsg",
          title: "魔法云",
          desc: document.title.split('-')[1] || '在线教育直播-知识付费-企业直播-网校系统-直播课堂',
          link: window.location.href,
          imgurl: "https://m.mfu.cn/m/static/20200622214647.png"
        },
        result => {

        }
      );
    }
  );
  next();
});
export default router